package cn.hf.mychat.config;

import lombok.Data;
import lombok.ToString;

@ToString
@Data
public class Result<T> {
    /**
     * 返回状态码
     */
    private Integer code;
    /**
     * 返回描述消息
     */
    private String message;
    /**
     * 返回数据
     */
    private T data;

    public static final int OK = 200;  //成功相应吗

    public static final String SUCCESS_RESULT = "success"; //成功描述消息

    public static final String ERROR_RESULT = "error";

    public Result(T data){
     this(OK,data,SUCCESS_RESULT);
    }

    public Result(int code, T data, String message) {
        this.code = code;
        this.data = data;
        this.message = message;
    }

    public static <T> Result<T> success(T data) {
        return new Result<>(OK, data, SUCCESS_RESULT);
    }

    public static <T> Result<T> error(T data) {
        return new Result<>(OK, data, ERROR_RESULT);
    }
}
